import java.util.StringTokenizer;

class P10300 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		for (int k = 0; k < cases; k++) {
			process();
		}
	}

	private static void process() {
		int numberofFarmers = Integer.parseInt(readLn());
//		int[][] farmer = new int[numberofFarmers][3];
		double burden = 0;
		for (int k = 0; k < numberofFarmers; k++) {
			StringTokenizer st = new StringTokenizer(readLn());
//			farmer[k][0] = Integer.parseInt(st.nextToken());
//			farmer[k][1] = Integer.parseInt(st.nextToken());
//			farmer[k][2] = Integer.parseInt(st.nextToken());
			double x  = new Double(st.nextToken()).doubleValue();
			double y  = new Double(st.nextToken()).doubleValue();
			double z  = new Double(st.nextToken()).doubleValue();

			burden += ((x / y) * z) * y;
		}
		System.out.println((int)burden);

	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}